package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.IBMSProtocol;
import keeto.com.vn.bms.network.request.GetListProductRequest;
import keeto.com.vn.bms.network.response.GetListProductsResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetListProduct extends AbstractTask{
	private int pageLimit;
	private int pageNumber;
	public TaskGetListProduct(BMSListener listener, IBMSCore core, int pageLimit, int pageNumber) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.pageLimit=pageLimit;
		this.pageNumber=pageNumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetListProductRequest request= new GetListProductRequest();
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetListProductsResponse response=protocol.getListProducts(request);
		for(BMSListener mListener:listener){
			mListener.finishGetListProducts(response.getReturnCode(), response.getCountPage(), response.getListProducts());
		} 
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for(BMSListener mListener:listener){
			mListener.finishGetListProducts(IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, 0, null);
		} 
	}

}
